Various applications require rounding of signed numbers divided by an integer power of two, e.g., 1, 2, 4, 8, 16, etc. Rounding implies integer division with rounding to the nearest integer. Half integer values are rounded away from 0. For example, 3/2 is rounded to 2, while − 3/2 is rounded to −2.
Rounding of unsigned numbers can be achieved by addition along with the right shift operation. The value that is required to be added to a numerator and the number of times right shift has to be performed is equal to the log2 of the denominator. For example, if 14 (01110) is to be rounded by four, log24=2 (10) is added, resulting in 16 (10000). The result is then right shifted twice, resulting in 100, or four.
Although the foregoing scheme works for unsigned binary numbers, it does not yield correct results for signed binary numbers. This is because of the fact that in two's complement representation of signed binary numbers, the sign bit (most significant bit) of the numbers carries a negative weight. Thus if 10010 (−14) has to be rounded by 100 (4), the result should be −4. However, the foregoing scheme results in 101 (−3).
One way to achieve rounding of signed binary numbers is to convert the signed number to unsigned numbers (preserving the sign information), round the unsigned numbers, and apply to sign information. The foregoing adds additional steps of converting each signed number to unsigned number, requiring more processing, and more time.
Further limitations and disadvantages of conventional and traditional approaches will become apparent to one of skill in the art, through comparison of such systems with embodiments presented in the remainder of the present application with references to the drawings.